package Code.Day2_20240919.com.dx.day02;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.List;

/**
 * @ClassName LambdaPerson
 * @Description Lambda表达式
 * @Author 12994
 * @Date 2024/9/19 18:00
 * @Version 1.0
 **/
@Getter
@AllArgsConstructor
public class LambdaPerson {
    private String name;
    private int age;

    @FunctionalInterface
    interface FirstNameChecker {
        boolean makeCheck(LambdaPerson person);
    }

    @FunctionalInterface
    interface AgePrinter {
        void makePrint(LambdaPerson person);
    }

    private static void checkAndPrinter(List<LambdaPerson> people,
                                        FirstNameChecker firstNameChecker,
                                        AgePrinter agePrinter) {
//        for (LambdaPerson p : people) {
//            if (firstNameChecker.makeCheck(p)) {
//                agePrinter.makePrint(p);
//            }
//        }
        people.forEach(p -> {
            firstNameChecker.makeCheck(p);
            agePrinter.makePrint(p);
        });
    }

    public static void main(String[] args) {
        List<LambdaPerson> people = Arrays.asList(
                new LambdaPerson("张三", 25),
                new LambdaPerson("李四", 40),
                new LambdaPerson("张五", 40)
        );


        checkAndPrinter(people, person -> person.name.startsWith("张"),
                person -> System.out.println(person.age));
    }


}
